package com.example.administrator.u17.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.u17.R;
import com.example.administrator.u17.model.QiangLiTuiJianMoreComics;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/11/15.
 */

public class QiangLiTuiJianMoreAdapter extends BaseAdapter{
    private Context context;
    private List<QiangLiTuiJianMoreComics> list;

    public QiangLiTuiJianMoreAdapter(Context context, List<QiangLiTuiJianMoreComics> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        QiangLiTuijianMoreViewHolder holder;
        if (convertView==null){
            convertView=View.inflate(context,R.layout.item_qianglituijian_more,null);
            holder=new QiangLiTuijianMoreViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder=(QiangLiTuijianMoreViewHolder)convertView.getTag();
        }
        QiangLiTuiJianMoreComics qiangLiTuiJianMoreComics = list.get(position);
        holder.tvTitle.setText(qiangLiTuiJianMoreComics.name);
        StringBuilder builder=new StringBuilder();
        for (int i = 0; i < qiangLiTuiJianMoreComics.tags.size(); i++) {
            builder.append(qiangLiTuiJianMoreComics.tags.get(i));
        }
        holder.tvTags.setText(builder);
        holder.tvContent.setText(qiangLiTuiJianMoreComics.description);
        holder.tvTime.setVisibility(View.GONE);
        Picasso.with(context).load(qiangLiTuiJianMoreComics.cover).into(holder.ivBig);
        return convertView;
    }

    class QiangLiTuijianMoreViewHolder{
        TextView tvTitle,tvTags,tvContent,tvTime;
        ImageView ivBig;
        public QiangLiTuijianMoreViewHolder(View view){
            tvTitle= (TextView) view.findViewById(R.id.tv_item_qianglituijian_more_title);
            tvTags=(TextView)view.findViewById(R.id.tv_item_qianglituijian_more_tags);
            tvContent=(TextView)view.findViewById(R.id.tv_item_qianglituijian_more_content);
            tvTime=(TextView)view.findViewById(R.id.tv_item_qianglituijian_more_time);
            ivBig=(ImageView)view.findViewById(R.id.iv_item_qianglituijian_more);
        }
    }
}
